//
//  UserEquipController.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/26.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "UserEquipController.h"
#import "UserGroup.h"
#import "UserArrowItem.h"
#import "UserSaveItem.h"
#import "UserCenterCell.h"
#import "UserBrandController.h"
#import "UserNameController.h"
#import "UserSeriesViewModel.h"
#import "UserTwoColumnPickerVC.h"
#import "UserTennisLineVC.h"
#import "UserImageItem.h"
#import "PhotoActionSheetViewController.h"
#import "UserEquipModel.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/SDImageCache.h>
#import "NSDate+FormateString.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import "UIImage+Resize.h"
#import "NSString+Extension.h"
#import "UserSericesChildVC.h"

#define arcWitch [UIScreen mainScreen].bounds.size.width/2

NSString *const userChangeUserEquipNotification = @"userChangeUserEquipNotification";

@interface UserEquipController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic, strong) UserEquipModel *equipModle;

/** 当前选择照片的indexPath */
@property (nonatomic, strong) NSIndexPath *selectImageIndexPath;

@property (nonatomic, copy)NSString *Brand; //球拍品牌


@property (nonatomic, copy)NSString *BuyTime; //球拍购买日期
@property (nonatomic, copy)NSString *VerticalLine; //竖线


@property (nonatomic, copy)NSString *vLineBrand; //品牌
@property (nonatomic, copy)NSString *vLineModel; // 类型
@property (nonatomic, copy)NSString *vLineSize;// 规格
@property (nonatomic, copy)NSString *vLineTenssion; // 张力

@property (nonatomic, copy)NSString *Line; //横线

@property (nonatomic, copy)NSString *hLineBrand; //品牌
@property (nonatomic, copy)NSString *hLineModel; // 类型
@property (nonatomic, copy)NSString *hLineSize;// 规格
@property (nonatomic, copy)NSString *hLineTenssion; // 张力

@property (nonatomic, copy)NSString *ShoesName; //球鞋名称
@property (nonatomic, copy)NSString *ShoesBuyTime; //球拍购买日期
@property (nonatomic, copy)NSString *ShoesUrl; //球鞋url图片
@property (nonatomic, copy)NSString *RacketUrl; //球拍url图片

@property (nonatomic, strong)UIImage *changeRacketImage;
@property (nonatomic, strong)UIImage *changeShoesImage;

@end

@implementation UserEquipController {
    UserSeriesViewModel *_seriesViewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _seriesViewModel = [UserSeriesViewModel shareInstance];
    self.equipModle = [User getLastUser].userEquipModel;
    
    [self configerUserEquipInfro];
    
    [self loadData];
    
    // 添加通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUserEquipsNotification:) name:userChangeUserEquipNotification object:nil];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"user_icon_save"] style:UIBarButtonItemStylePlain target:self action:@selector(saveEquipInfro)];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

- (void)configerUserEquipInfro {
    self.Brand = self.equipModle.Brand;
    self.BuyTime = self.equipModle.BuyTime;
    self.VerticalLine = self.equipModle.VerticalLine;
    self.Line = self.equipModle.Line;
    self.ShoesName = self.equipModle.ShoesName;
    self.ShoesBuyTime = self.equipModle.ShoesBuyTime;
    self.ShoesUrl = self.equipModle.ShoesUrl;
    self.RacketUrl = self.equipModle.RacketUrl;
}
- (void)operatoionUserEquipInfo {
    RLMRealm *realm = [RLMRealm defaultRealm];
    [realm beginWriteTransaction];
    self.equipModle.Brand = self.Brand;
    self.equipModle.BuyTime = self.BuyTime;
    self.equipModle.VerticalLine = self.VerticalLine;
    self.equipModle.Line = self.Line;
    self.equipModle.ShoesName = self.ShoesName;
    self.equipModle.ShoesBuyTime = self.ShoesBuyTime;
    self.equipModle.ShoesUrl = self.ShoesUrl;
    self.equipModle.RacketUrl = self.RacketUrl;
    [realm commitWriteTransaction];
}

- (void)saveEquipInfro {
    
     MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    YFUserApi *saveEquipApi = [YFUserApi performSaveEquipInfoWithBrand:self.Brand
                                                               buyTime:self.BuyTime verticalLine:self.VerticalLine
                                                                  line:self.Line
                                                             shoesName:self.ShoesName
                                                          shoesBuyTime:self.ShoesBuyTime];
    
    [[YFNetworkingService sharedInstance] sendRequest:saveEquipApi callback:^(BOOL success, id result, NSError *error) {
        // NSLog(@"%zd %@", saveEquipApi.responseStatusCode,result);
        if (success) {
            [hud hideAnimated:YES];
            [self operatoionUserEquipInfo];
            if (self.changeShoesImage) {
                [self saveSelectEquipImage:self.changeShoesImage isRactet:NO complete:^(BOOL isSeccuss, NSString *imageUrl) {
                    if (isSeccuss) {
                        self.ShoesUrl = imageUrl;
                    }
                }];
            }
            if(self.changeRacketImage){
                [self saveSelectEquipImage:self.changeRacketImage isRactet:YES complete:^(BOOL isSeccuss, NSString *imageUrl) {
                    if (isSeccuss) {
                        self.RacketUrl = imageUrl;
                    }
                    
                }];
            }
            
            [hud showSuccessHudInView:[UIApplication sharedApplication].keyWindow message:NSLocalizedString(@"Successfully Saved", nil)  afterDelay:1.2];
            [self.navigationController popViewControllerAnimated:YES];
            
        }else {
            [hud showTextHUDWithMessage:NSLocalizedString(@"Fail", nil) inView:self.view];
        }
    }];
    
}

- (void)saveSelectEquipImage:(UIImage *)image isRactet:(BOOL)isRactet complete:(void(^)(BOOL isSeccuss, NSString *imageUrl))complete {
    // MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    if (isRactet) {
      [YFUserApi uploadImageWithRequestType:KUserUploadRactetImageApi withImage:image complete:^(NSError *error, NSString *imageUrl) {
            if (error == nil) {
                //  [hud hide:YES];
                RLMRealm *realm = [RLMRealm defaultRealm];
                [realm beginWriteTransaction];
                self.equipModle.RacketUrl = imageUrl;
                [realm commitWriteTransaction];
                complete(YES, imageUrl);
            } else {
                // [hud showTextHUDWithMessage:NSLocalizedString(@"Fail", nil) inView:self.view];
                complete(NO, nil);
            }
        }];
        
    }else {
        [YFUserApi uploadImageWithRequestType:KUserUploadShoeImageApi withImage:image complete:^(NSError *error, NSString *imageUrl) {
            if (error == nil) {
                // [hud hide:YES];
                RLMRealm *realm = [RLMRealm defaultRealm];
                [realm beginWriteTransaction];
                self.equipModle.ShoesUrl = imageUrl;
                [realm commitWriteTransaction];
                complete(YES, imageUrl);
            } else {
                // [hud showTextHUDWithMessage:NSLocalizedString(@"Fail", nil) inView:self.view];
                complete(NO, nil);
            }
        }];
    }

}

- (void)changeUserEquipsNotification:(NSNotification *)note {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    UserGroup *group = self.groups[indexPath.section];
    UserItem *item = group.items[indexPath.row];
    
    item.subTitle = [NSString stringWithFormat:@"%@\n%@", note.userInfo[@"Brand"], note.userInfo[@"Model"]];
    self.Brand = [NSString stringWithFormat:@"%@,%@", note.userInfo[@"Brand"], note.userInfo[@"Model"]];
    
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - <从手机中选择图片>
- (void)setHeadIcon {
    __weak typeof(self) weakSelf = self;
    [PhotoActionSheetViewController showInParentViewController:self animationType:DetailViewControllerPresentAnimationTypeUp actionBlock:^(kTapActionButtonType btnType) {
        if (btnType == kTapAlbumButton) {
            [weakSelf takePhotoByPhotos];
        } else  if (btnType == kTapCameraButton) {
            [weakSelf takePhotoByCamera];
        }else {
            [weakSelf.tableView reloadRowsAtIndexPaths:@[weakSelf.selectImageIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    }];
}

- (void)takePhotoByCamera{
    
    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
        [MBProgressHUD showTextHUDWithMessage:NSLocalizedString(@"Can't get camera or photo information", nil) inView:self.view];
        return;
    }
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;
    
    [picker setAllowsEditing:YES];
    [self presentViewController:picker animated:YES completion:nil];
}

- (void)takePhotoByPhotos {
    
    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        [MBProgressHUD showTextHUDWithMessage:NSLocalizedString(@"Can't get camera or photo information", nil) inView:self.view];
        return;
    }
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
        
    [picker setAllowsEditing:YES];
    [self presentViewController:picker animated:YES completion:nil];
}

#pragma mark - UIImagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

    [picker dismissViewControllerAnimated:YES completion:nil];
    
    UserGroup *group = self.groups[self.selectImageIndexPath.section];
    UserImageItem *imageItem = (UserImageItem *)group.items[self.selectImageIndexPath.row];
    
    BOOL isRactet = self.selectImageIndexPath.section == 0 ? YES :NO;
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    UIImage *image2 = [UIImage imagewithImage:image];
    image2 = [image2 resizedImageWithBounds:CGSizeMake(image2.size.width, image2.size.height)];
    imageItem.image = image2;
    
    if (isRactet) {
        self.changeRacketImage = image2;
    }else {
        self.changeShoesImage = image2;
    }
    [self.tableView reloadRowsAtIndexPaths:@[self.selectImageIndexPath] withRowAnimation:UITableViewRowAnimationNone];
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//    NSLog(@"%@",navigationController.viewControllers);
    if (@available(iOS 11.0, *)) {
    }else {
        if (navigationController.viewControllers.count == 3)
        {
            UIPageViewController *curImageVc = navigationController.viewControllers[2];
            curImageVc.title = [NSBundle currentLanguageIsChinese] ? @"移动和缩放":@"Move and scale";
            Method method = class_getInstanceMethod([self class], @selector(drawRect:));
            class_replaceMethod([[[[navigationController viewControllers][2].view subviews][1] subviews][0] class],@selector(drawRect:),method_getImplementation(method),method_getTypeEncoding(method));
        }
    }
}

-(void)drawRect:(CGRect)rect
{
    CGContextRef ref = UIGraphicsGetCurrentContext();
    CGContextAddRect(ref, rect);
    CGContextAddArc(ref, [UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2, arcWitch, 0, M_PI*2, NO);
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]setFill];
    CGContextDrawPath(ref, kCGPathEOFill);
    
    CGContextAddArc(ref, [UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2, arcWitch, 0, M_PI*2, NO);
    [[UIColor whiteColor]setStroke];
    CGContextStrokePath(ref);
}

- (void)loadData {
    __weak typeof(self) weakSelf = self;
    
    UIImageView *imageView1 = [[UIImageView alloc] init];
    
    //    第一组
    UserGroup *group0 = [[UserGroup alloc] init];
    group0.headerTitle = NSLocalizedString(@"Racket", nil);
    group0.headHeight = kAutoHei(30);
    
    [imageView1 sd_setImageWithURL:[NSURL URLWithString:self.equipModle.RacketUrl] placeholderImage:[UIImage imageNamed:@"user_camera"]];
    
    UserImageItem *item0_0 = [UserImageItem initWithTitle:NSLocalizedString(@"User.Picture", @"图片") andImagePath:self.equipModle.RacketUrl];
    
    
    // 选择图片
    [item0_0 setBlock:^{
        [weakSelf setHeadIcon];
        weakSelf.selectImageIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    }];
    
    NSArray *brand = [self.equipModle.Brand componentsSeparatedByString:@","];
    NSString *brandStr = self.equipModle.Brand;
    if (brand.count >= 2) {
        brandStr = [NSString stringWithFormat:@"%@\n%@", brand[0], brand[1]];
    }
    
    UserArrowItem *item0_1 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Brand and Model", nil) andSubTitle:brandStr andTarget:[UserBrandController class]];
    //  如果连接的是海德的设备直接跳转到head的子界面
    if ([User getLastUser].userDevice.oemType == OemTypeHD){
        item0_1 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Brand and Model", nil) andSubTitle:brandStr andTarget:nil];
        NSArray *brandAndModelArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RacketBrandAndModel.plist" ofType:nil]];
        NSDictionary *obj = brandAndModelArray.firstObject;
        [item0_1 setBlock:^{
            UserSericesChildVC *childVc = [[UserSericesChildVC alloc] init];
            childVc.childType = SericesChildBrandAndModle;
            childVc.content = obj[@"RacketBrand"];
            [childVc.groups addObject:[weakSelf racketModelArray:obj[@"RacketModel"]]];
            [weakSelf.navigationController pushViewController:childVc animated:YES];
        }];
    }
    
    UserArrowItem *item0_2 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Purchase Date", nil) andSubTitle:[self chineseFormatbuyTime:self.equipModle.BuyTime] andTarget:nil];
    
    __weak typeof(item0_2) weakItem0_2 = item0_2;
    [item0_2 setBlock:^{
        UserTwoColumnPickerVC *pickerVc = [[UserTwoColumnPickerVC alloc] init];
        pickerVc.contentKey = weakItem0_2.title;
        if (weakItem0_2.subTitle.length >= 5) {
            pickerVc.firstColValue = [weakItem0_2.subTitle substringToIndex:5];
            pickerVc.secondColValue = [weakItem0_2.subTitle substringFromIndex:5];
        }
       
        pickerVc.pickerDataSource = [_seriesViewModel yearAndMonthArr];
       
        [pickerVc setSelectCallback:^(NSString *callBackString) {
            weakItem0_2.subTitle = callBackString;
                        
            NSString *buyTimeStr = [callBackString trimingAllNumber];
            if (callBackString.length >= 6) {
                buyTimeStr = [NSString stringWithFormat:@"%@-%@",[buyTimeStr substringToIndex:4], [buyTimeStr substringFromIndex:4]];
            }else {
                buyTimeStr = @"";
            }
            weakSelf.BuyTime = buyTimeStr;
            [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:2 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
        }];
        
        [weakSelf.navigationController pushViewController:pickerVc animated:YES];
    }];
    
    // 横线
    NSString *hlineSubTitle = [NSString stringWithFormat:@"%@ %@ %@%@",self.hLineBrand, self.hLineSize, [self.hLineTenssion trimingAllNumber],NSLocalizedString(@"Unit.lbs", @"磅")];
    if (self.hLineSize.length == 0 && [self.hLineTenssion trimingAllNumber].length == 0) {
        hlineSubTitle = @"";
    }
    UserArrowItem *item0_4 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Cross Strings", nil) andSubTitle:hlineSubTitle andTarget:nil];
    
    __weak typeof(item0_4) weakItem0_4 = item0_4;
    [item0_4 setBlock:^{
        UserTennisLineVC *horizontalVC = [[UserTennisLineVC alloc] init];
        horizontalVC.title = weakItem0_4.title;
        horizontalVC.brandStr = self.hLineBrand;
        horizontalVC.modelStr = self.hLineModel;
        horizontalVC.sizeStr = self.hLineSize;
        horizontalVC.tensionStr = self.hLineTenssion;
        
        [horizontalVC setSelectCallback:^(NSString *brand, NSString *model, NSString *size, NSString *tension) {
            weakSelf.hLineBrand = brand;
            weakSelf.hLineModel = model;
            weakSelf.hLineSize = size;
            weakSelf.hLineTenssion = tension;
            weakItem0_4.subTitle = [NSString stringWithFormat:@"%@ %@ %@",brand, size, tension];
            weakSelf.Line = [NSString stringWithFormat:@"%@,%@,%@,%@",brand, model, size, tension];
            [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:4 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
        }];
        
        [weakSelf.navigationController pushViewController:horizontalVC animated:YES];
    }];
    
    // 竖线
    NSString *vlineSubTitle = [NSString stringWithFormat:@"%@ %@ %@%@",self.vLineBrand, self.vLineSize, [self.vLineTenssion  trimingAllNumber], NSLocalizedString(@"Unit.lbs", @"磅")];
    if (self.vLineSize.length == 0 && [self.vLineTenssion trimingAllNumber].length == 0) {
        vlineSubTitle = @"";
    }
    UserArrowItem *item0_3 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Main Strings", nil) andSubTitle:vlineSubTitle andTarget:nil];
    
    __weak typeof(item0_3) weakItem0_3 = item0_3;
    [item0_3 setBlock:^{
        UserTennisLineVC *verticalVC = [[UserTennisLineVC alloc] init];
        verticalVC.title = weakItem0_3.title;
        verticalVC.brandStr = self.vLineBrand;
        verticalVC.modelStr = self.vLineModel;
        verticalVC.sizeStr = self.vLineSize;
        verticalVC.tensionStr = self.vLineTenssion;
        
        [verticalVC setSelectCallback:^(NSString *brand, NSString *model, NSString *size, NSString *tension) {
            weakSelf.vLineBrand = brand;
            weakSelf.vLineModel = model;
            weakSelf.vLineSize = size;
            weakSelf.vLineTenssion = tension;
            weakItem0_3.subTitle = [NSString stringWithFormat:@"%@ %@ %@",brand, size, tension];
            weakSelf.VerticalLine = [NSString stringWithFormat:@"%@,%@,%@,%@",brand, model, size, tension];
         
            // 修改竖线，连同一起修改横线
            weakSelf.hLineBrand = brand;
            weakSelf.hLineModel = model;
            weakSelf.hLineSize = size;
            weakSelf.hLineTenssion = tension;
            weakItem0_4.subTitle = [NSString stringWithFormat:@"%@ %@ %@",brand, size, tension];
            weakSelf.Line = [NSString stringWithFormat:@"%@,%@,%@,%@",brand, model, size, tension];
            
            [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:0], [NSIndexPath indexPathForRow:4 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
        }];
    
        [weakSelf.navigationController pushViewController:verticalVC animated:YES];
    }];
    
    [group0.items addObjectsFromArray:@[item0_0, item0_1, item0_2,item0_3, item0_4]];
    [self.groups addObject:group0];
    
    //    第二组
    UserGroup *group1 = [[UserGroup alloc] init];
    group1.headerTitle = NSLocalizedString(@"User.Shoes", nil); // 球鞋
    group1.headHeight = kAutoHei(30);
    
    UIImageView *imageView2 = [[UIImageView alloc] init];
    
    [imageView2 sd_setImageWithURL:[NSURL URLWithString:self.equipModle.ShoesUrl] placeholderImage:[UIImage imageNamed:@"user_camera"]];
    
    UserImageItem *item1_0 = [UserImageItem initWithTitle:NSLocalizedString(@"User.Picture", @"图片") andImagePath:self.equipModle.ShoesUrl];
    
    
    
    [item1_0 setBlock:^{
        [weakSelf setHeadIcon];
        weakSelf.selectImageIndexPath = [NSIndexPath indexPathForRow:0 inSection:1];
    }];
    
    UserArrowItem *item1_1 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"User.Model Name", nil) andSubTitle:self.equipModle.ShoesName andTarget:nil];
    __weak typeof(item1_1) weakItem1_1 = item1_1;
    
    [item1_1 setBlock:^{
        UserNameController *nameVC = [[UserNameController alloc] init];
        nameVC.title = weakItem1_1.title;
        nameVC.userName = weakItem1_1.subTitle;
        
        [nameVC setUserNameBlock:^(NSString *text) {
            weakItem1_1.subTitle = text;
            weakSelf.ShoesName = text;
            [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
        }];
        
        [weakSelf.navigationController pushViewController:nameVC animated:YES];
    }];
    

    UserArrowItem *item1_2 = [UserArrowItem itemWithIcon:nil andTitle:NSLocalizedString(@"Purchase Date", nil) andSubTitle:[self chineseFormatbuyTime:self.equipModle.ShoesBuyTime] andTarget:nil];
    __weak typeof(item1_2) weakItem1_2 = item1_2;
    [item1_2 setBlock:^{
        UserTwoColumnPickerVC *pickerVc = [[UserTwoColumnPickerVC alloc] init];
        pickerVc.contentKey = weakItem1_2.title;
        if (weakItem1_2.subTitle.length >= 5) {
            pickerVc.firstColValue = [weakItem1_2.subTitle substringToIndex:5];
            pickerVc.secondColValue = [weakItem1_2.subTitle substringFromIndex:5];
        }
       
        pickerVc.pickerDataSource = [_seriesViewModel yearAndMonthArr];
        
        [pickerVc setSelectCallback:^(NSString *callBackString) {
            weakItem1_2.subTitle = callBackString;
            NSString *shoeBuyTimeStr = [callBackString trimingAllNumber];
            if (callBackString.length >= 6) {
               shoeBuyTimeStr = [NSString stringWithFormat:@"%@-%@",[shoeBuyTimeStr substringToIndex:4], [shoeBuyTimeStr substringFromIndex:4]];
            }else {
                shoeBuyTimeStr = @"";
            }
            
            weakSelf.ShoesBuyTime = shoeBuyTimeStr;
            
            [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:2 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
        }];
        
        [weakSelf.navigationController pushViewController:pickerVc animated:YES];
    }];
    
    [group1.items addObjectsFromArray:@[item1_0, item1_1, item1_2]];
    [self.groups addObject:group1];
    
}

- (NSString *)chineseFormatbuyTime:(NSString *)buyTimeStr {
    if (buyTimeStr.length >= 5) {
        NSString *shoesYear = [buyTimeStr substringToIndex:4];
        NSString *shoesMonth = [buyTimeStr substringFromIndex:5];
        if ([NSBundle currentLanguageIsChinese]) {
           return [NSString stringWithFormat:@"%@年%@月",shoesYear, shoesMonth];
        }else{
            return buyTimeStr;
        }
    }else {
        return buyTimeStr;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UserCenterCell *cell = [UserCenterCell settingViewCellTableView:tableView withStyle:UITableViewCellStyleValue1];
    
    UserGroup *group = self.groups[indexPath.section];
    UserItem *item = group.items[indexPath.row];
    cell.item = item;
    if (indexPath.row == group.items.count - 1) {
        [cell showLine:NO];
    }else {
        [cell showLine:YES];
    }
    if (indexPath.row == 0) {
        [cell showSectionSepTopLineView:YES];
    }else {
        [cell showSectionSepTopLineView:NO];
    }
    
    return cell;
}

// 选中的哪一行


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0 || indexPath.row == 1) {
            return 64;
        }else {
            return 44;
        }
    }else {
        if (indexPath.row == 0) {
            return 64;
        }else {
           return 44;
        }
    }
    
}

- (UserGroup *)racketModelArray:(NSArray *)stringArr {
    
    UserGroup *group0 = [[UserGroup alloc] init];
    
    group0.headHeight = kAutoHei(24);
    
    [stringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UserSaveItem *saveItem = [UserSaveItem itemWithTitle:obj];
        [group0.items addObject:saveItem];
    }];
    
    return group0;
}


#pragma mark - getter & setter

- (void)setVerticalLine:(NSString *)VerticalLine {
    _VerticalLine = VerticalLine;
    
     NSArray *array = [VerticalLine componentsSeparatedByString:@","];
    if (array.count >= 4) {
        self.vLineBrand = array[0];
        self.vLineModel = array[1];
        self.vLineSize = array[2];
        self.vLineTenssion = array[3];
    }
}
- (void)setLine:(NSString *)Line {
    _Line = Line;
    NSArray *array = [Line componentsSeparatedByString:@","];
    if (array.count >= 4) {
        self.hLineBrand = array[0];
        self.hLineModel = array[1];
        self.hLineSize = array[2];
        self.hLineTenssion = array[3];
    }
}

- (NSString *)vLineSize {
    if (_vLineSize == nil) {
        return @"";
    }
    return _vLineSize;
}
- (NSString *)vLineTenssion {
    if (_vLineTenssion == nil) {
        return @"";
    }
    return _vLineTenssion;
}
- (NSString *)vLineBrand {
    if (_vLineBrand == nil) {
        return @"";
    }
    return _vLineBrand;
}
- (NSString *)vLineModel {
    if (_vLineModel == nil) {
        return @"";
    }
    return _vLineModel;
}
- (NSString *)hLineSize {
    if (_hLineSize == nil) {
        return @"";
    }
    return _hLineSize;
}
- (NSString *)hLineTenssion {
    if (_hLineTenssion == nil) {
        return @"";
    }
    return _hLineTenssion;
}
- (NSString *)hLineBrand {
    if (_hLineBrand == nil) {
        return @"";
    }
    return _hLineBrand;
}
- (NSString *)hLineModel {
    if (_hLineModel == nil) {
        return @"";
    }
    return _hLineModel;
}

@end
